package com.example.myapplication2.app;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

public class MultipleActivity extends Activity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_multiple);
        Button btn = (Button) findViewById(R.id.btn_toast);
        btn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_toast:
                ProgressBar bar = (ProgressBar) findViewById(R.id.pbar);
                EditText text = (EditText) findViewById(R.id.edit_text);
                int progress = bar.getProgress();
                progress += 10;
                if (progress == 100) {
                    bar.setVisibility(View.GONE);
                    AlertDialog.Builder alert = new AlertDialog.Builder(MultipleActivity.this);
                    alert.setTitle("进度条完成");
                    alert.setMessage("进度完成了");
                    alert.setCancelable(false);
                    alert.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });
                    alert.setNegativeButton("关闭", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    alert.show();
                }
                bar.setProgress(progress);
                Toast.makeText(MultipleActivity.this, text.getText(), Toast.LENGTH_SHORT).show();
                break;
        }
    }

}
